package com.tcoiss.kettle.core.init;

import lombok.extern.log4j.Log4j2;
import com.tcoiss.kettle.common.utils.FileUtil;
import com.tcoiss.kettle.common.utils.StringUtil;
import org.pentaho.di.core.KettleEnvironment;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Properties;

/**
 * kettle初始化
 *
 * @author lyf
 */
@Component
@Log4j2
public class KettleInit implements InitializingBean {
	@Autowired
    com.tcoiss.kettle.core.constant.KettleConfig KettleConfig;

	@Override
	public void afterPropertiesSet() throws Exception {
		// 自定义环境初始化
		environmentInit();
		// kettle环境初始化
		KettleEnvironment.init();
	}

	private void environmentInit() {
		log.info("KETTLE HOME:"+KettleConfig.kettleHome);
		Properties properties = System.getProperties();
		properties.put("KETTLE_HOME", KettleConfig.kettleHome);
		if (StringUtil.hasText(KettleConfig.kettlePluginPackages)) {
			log.info("KETTLE_PLUGIN_PACKAGES:"+KettleConfig.kettlePluginPackages);
			properties.put("KETTLE_PLUGIN_PACKAGES", FileUtil.replaceSeparator(KettleConfig.kettlePluginPackages));
		}
		/*if (StringUtil.hasText(KettleConfig.kettlePluginBaseFolder)) {
			log.info("KETTLE_PLUGIN_BASE_FOLDERS:"+KettleConfig.kettlePluginBaseFolder);
			properties.put("KETTLE_PLUGIN_BASE_FOLDERS", FileUtil.replaceSeparator(KettleConfig.kettlePluginBaseFolder));
			//System.setProperty("KETTLE_PLUGIN_BASE_FOLDERS", KettleConfig.kettlePluginBaseFolder);
		}*/

	}
}
